<!-- /*
 * @Author: RDSunday 
 * @Date: 2020-03-16 17:04:45 
 * @Last Modified by:   RDSunday 
 * @Last Modified time: 2020-03-16 17:04:45 
 */ -->
<!-- 动画应用实例 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #myContent{
            width: 400px;
            height: 400px;
            position: relative;
            background-color: yellow;
        }
        #myAnimation {
            width: 50px;
            height: 50px;
            position: absolute;
            background-color: red;
        }
    </style>
</head>
<body>
    <button onclick="myMove()">点我</button> 
    <div id="myContent">
        <div id="myAnimation"></div>
    </div>
    <script>
        function myMove() {
            var elem = document.getElementById("myAnimation");
            var pos = 0;
            var id = setInterval(frame, 10);//返回的ID用作clearInterval（）方法的参数
            function frame() {
                if (pos ==350) {
                    clearInterval(id);
                }else {
                    pos++;
                    elem.style.top = pos + 'px';
                    elem.style.left = pos + 'px';
                }
            }
        }
    </script>
       
</body>
</html>